package com.example.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Aspect   //标识为切面类
public class Tameout {
    //切入点
    @Around("execution(* com.example.service.impl.*.*(..))")
    public Object runtime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        // 记录开始时间
        long beging = System.currentTimeMillis();

        //运行方法
        Object object = proceedingJoinPoint.proceed();

        //记录结束时间
        long end = System.currentTimeMillis();
        log.info("运行方法耗时 {} ms",end - beging);

        return object;
    }
}
